package com.kvn.cucumber;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import org.junit.Assert;

/**
 * @author wzy on 2017/8/4.
 */
public class Add {
    Calculator calculator;

    @Given("^i input \"([^\"]*)\" and \"([^\"]*)\"$")
    public void iInputAnd(String arg0, String arg1) throws Throwable {
        // Write code here that turns the phrase above into concrete actions
        calculator = new Calculator();
        calculator.setNum1(Integer.parseInt(arg0));
        calculator.setNum2(Integer.parseInt(arg1));

    }

    @When("^the calculator is run$")
    public void theCalculatorIsRun() throws Throwable {
        // Write code here that turns the phrase above into concrete actions
        calculator.calculate();
    }

    @Then("^the out put should be \"([^\"]*)\"$")
    public void theOutPutShouldBe(String arg0) throws Throwable {
        // Write code here that turns the phrase above into concrete actions
        Assert.assertEquals(Integer.parseInt(arg0), calculator.getTotle());
    }


    class Calculator {
        private int num1;
        private int num2;
        private int totle;

        public int getNum1() {
            return num1;
        }

        public void setNum1(int num1) {
            this.num1 = num1;
        }

        public int getNum2() {
            return num2;
        }

        public void setNum2(int num2) {
            this.num2 = num2;
        }

        public int getTotle() {
            return num1 + num2;
        }

        public void calculate() {
            totle = num1 + num2;
        }
    }

}

